<template>
  <div class="User">
    <el-menu
        mode="horizontal"
        background-color="#545c64"
        text-color="#fff">
      <el-menu-item @click="gouser()">返回 </el-menu-item>
      <el-menu-item @click="unlogin()" style="position: fixed;right: 19px;top: 8px">注销</el-menu-item>
    </el-menu>
    <br><br>
    <el-button type="primary" style="position: relative;right: 5px" @click="search()">
      <span style="position: relative;right: 5px"> 搜索 </span>
    </el-button>
    <el-input
        v-model="input"
        placeholder="输入查询学号"
        style="width: 200px"
    />
    <br><br>
    <el-table :data="datas" stripe border style="width: 100%">
      <el-table-column prop="nickname" label="学生姓名"></el-table-column>
      <el-table-column prop="sex" label="性别"></el-table-column>
      <el-table-column prop="score" label="成绩" ></el-table-column>
      <el-table-column prop="age" label="年龄" ></el-table-column>
      <el-table-column prop="attend" label="缺勤" ></el-table-column>
      <el-table-column label="操作" width="500px" prop="userId">
        <template v-slot="scope">
          <el-input
              v-model="scope.row.inputgrade"
              placeholder="输入成绩"
              style="width: 200px;position: relative"
          />
          <el-button type="primary" style="position: relative;right: -30px" @click="revisegrade(scope.row.inputgrade,scope.row.userId)">
            <span style="position: relative;right: 2px"> 提交 </span>
          </el-button>
          <br><br>
          <el-input
              v-model="scope.row.inputattend"
              placeholder="输入考勤"
              style="width: 200px;position: relative"
          />
          <el-button type="primary" style="position: relative;right: -30px" @click="reviseattend(scope.row.inputattend,scope.row.userId)">
            <span style="position: relative;right: 2px"> 提交 </span>
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import global from "../plugins/axios";

export default {
  created() {
    axios.get('/user_course/findStudentCourseByCourseId/'+global.courseId,{},{withCredentials:true}).then(res=>{
      console.log(res);
      this.datas=res.data.data;
    })
  },
  data(){
    return{
      datas:[],
    }
  },
  methods:{
    reviseattend(attend,userId){
      axios.post('/user_course/addCourseAttend/'+userId+'/'+parseInt(global.courseId)+'/'+attend).then(res=>{
        //console.log(res)
        this.data=res
        axios.get('/user_course/findStudentCourseByCourseId/'+global.courseId,{},{withCredentials:true}).then(res=>{
          console.log(res);
          this.datas=res.data.data;
        })
      })
    },
    revisegrade(score,userId){
      axios.post('/user_course/addCourseGrade/'+userId+'/'+parseInt(global.courseId)+'/'+Number(score)).then(res=>{
        console.log(res)
        this.data=res.data.data;
        axios.get('/user_course/findStudentCourseByCourseId/'+global.courseId,{},{withCredentials:true}).then(res=>{
          //console.log(res);
          this.datas=res.data.data;
        })
      })
    },
    search(){
      axios.post('').then(res=>{
        console.log(res)
        this.data=res
      })
    },
    gouser() {
      this.$router.push('/user/teacherclass');
    },
    unlogin(){
      axios.post('/user/logout').then(res=> {
        if(res.data.code===10000){
          this.$message.success(res.data.msg);
          this.$router.push('/login');
        }else{
          this.$message.error(res.data.msg);
        }
      })
    }

  }
}
</script>

<style scoped>

</style>